<?php
//load requirements
include 'oneclick_core.php';
if(!current_user_can('manage_oneclick'))
    die('Access Denied');
include 'oneclick_parser.php';
$url=get_option("siteurl")."/wp-admin/admin.php"."?page=oneclick/frontend.php";
$oc_updatemessage="Test update message";
/////////////////////////
//FIRST, WE PROCESS THE POST AREA
/////////////////////////
if($_POST["oc_action"])
{
	$oc_post=$_POST["oc_action"];
	if($oc_post=="upload_hd")	
	{
		global $oc_upload_dir;
		$target_path = $oc_upload_dir;
		$target_name=basename( $_FILES['oc_uploadfile']['name']);
		$target_path = $target_path . basename( $_FILES['oc_uploadfile']['name']); 
		if(move_uploaded_file($_FILES['oc_uploadfile']['tmp_name'], $target_path)) {    	
		} else{
	    	die("There was an error uploading the file");
		}
		
			
		oc_process_file($target_path,$target_name);
				
	}
	if($oc_post=="confirm")
	{
		$conf_val=$_POST['oc_confirm'];
		$conf_filename=$_POST['oc_filename'];
		$conf_type=$_POST['oc_type'];
		$conf_path=$_POST['oc_filepath'];
		if($conf_val==1)
		{
			oc_upload($conf_filename,$conf_type,$conf_path);
		}
		if($conf_val==2)
		{
			oc_upload($conf_filename,$conf_type,$conf_path,1);				
		}
		if($conf_val==3)
		{
			oc_clear_directory($oc_upload_dir,"*");
		}
		if($conf_val==4)
		{
			oc_upload($conf_filename,'plugin','');
		}
		if($conf_val==5)
		{
			oc_upload($conf_filename,'theme','');				
		}
		
	}
}



?>
<?php if($oc_updatemessage){?><div id="update-message" class="updated fade"><p><?php echo $oc_updatemessage ?></p></div><?php }
?>
<?php
$oc_conf=oc_process_confirmation();
if($oc_conf!=0)
{
?>
<div class="wrap">
<h2>Upload confirmation:</h2>
Please confirm the details of the file you uploaded.<br />
<?php if($oc_conf['Type']=='plugin'){ ?>
The file <?php echo $oc_filename; ?> was detected as a <b>Plugin</b><br />
<h3>Details:</h3>
<b>Name</b>: <?php echo $oc_conf['Title']; ?><br />
<b>Author</b>: <?php echo $oc_conf['Author'] ?><br />
<b>Description</b>: <?php echo $oc_conf['Description']; ?><br />
<?php } 
?>
<?php if($oc_conf['Type']=='theme'){ ?>
The file <?php echo $oc_filename; ?> was detected as a <b>theme</b><br />
<h3>Details:</h3>
<b>Name</b>: <?php echo $oc_conf['Title']; ?><br />
<b>Author</b>: <?php echo $oc_conf['Author'] ?><br />
<b>Description</b>: <?php echo $oc_conf['Description']; ?><br />
<?php }
if($oc_conf==-1)
{
	?>
	The file <?php echo $oc_filename; ?> wasn't detected to be a theme or a plugin. If you don't know what it is, ignore or delete it. Otherwise you can force
	it to install either as a plugin or a theme.
	<?php
} 
?>
<br />
<br />
<form method="POST" action="<?php echo $url; ?>">
<h3>Select action to take</h3>
<?php if($oc_conf!=-1){ ?>
<input type="radio" name="oc_confirm" value="1" checked="checked">Upload<br />
<input type="radio" name="oc_confirm" value="2">Upload and Activate<br />
<?php } ?>
<input type="radio" name="oc_confirm" value="3" <?php if($oc_conf==-1){echo 'checked="checked"';} ?>>Ignore and delete<br />
<input type="radio" name="oc_confirm" value="2">Force as Plugin(advanced)(see help)(not recommended)<br />
<input type="radio" name="oc_confirm" value="2">Force as Theme(advanced)(see help)(not recommended)<br />
<input type="hidden" name="oc_action" value="confirm">
<input type="hidden" name="oc_filename" value="<?php echo $oc_filename; ?>">
<input type="hidden" name="oc_type" value="<?php echo $oc_conf['Type']; ?>">
<input type="hidden" name="oc_filepath" value="<?php echo $oc_conf['Path']; ?>">
<br />
<br />

<input type="submit" value="GO!" align="left" style="height=30;width=50" /></form>

</div><?php } ?>
<div class="wrap">
<h2>OneClick Installation</h2>
<?php show_zeitgeist(); ?>
To install a plugin or a theme, simply upload a ZIP file. OneClick will automatically determine wether the file is a plugin or a theme, and extract it in the right directory, and even activate it for you if you want :)
<h3>Step 1: Select method to upload ZIP File</h3>
<p class="submit" style="height: 52px; width: 493px;">
<input type="button" value="Upload From hard drive" style="margin-right: 21px; height: 49px; width: 212px;" onclick="javascript:document.getElementById('hd-upload').style.visibility='visible';javascript:document.getElementById('hd-upload').style.height='80px';document.getElementById('url-upload').style.visibility='hidden';javascript:document.getElementById('url-upload').style.height='0px';">
<input type="button" value="Enter URL" style="margin-left: 21px; width: 122px; height: 49px;" onclick="javascript:document.getElementById('hd-upload').style.visibility='hidden';javascript:document.getElementById('hd-upload').style.height='0px';document.getElementById('url-upload').style.visibility='visible';javascript:document.getElementById('url-upload').style.height='80px';">
</p>
<div id="hd-upload" style="visibility:hidden;height=0px">
<h3>Step 2: Browse for the ZIP File on your hard drive and click "GO!"</h3>
<form enctype="multipart/form-data" action="<?php echo $url; ?>" method="POST">
<input type="hidden" name="oc_action" value="upload_hd">
Choose a file to upload: <input name="oc_uploadfile" type="file" /><input type="submit" value="GO!" style="width: 80px;">
</form>
</div>
<div id="url-upload" style="visibility:hidden;height=0px">
<h3>Step 2: Enter or paste the URL of the ZIP file and click "GO!"</h3>
<form method="POST" action="<?php echo $url; ?>"><input type="hidden" name="oc_action" value="upload_url">
Enter URI: <input type="text" name="oc-url"><input type="submit" value="GO!" style="width: 80px;">
</form>
</div>
</div>